@use 'sass:math';
@use 'variables' as *;

// 文本溢出省略号
@mixin text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// 多行文本溢出省略号
@mixin text-ellipsis-multi($line: 2) {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: $line;
  overflow: hidden;
}

// flex布局
@mixin flex($direction: row, $justify: flex-start, $align: center) {
  display: flex;
  flex-direction: $direction;
  justify-content: $justify;
  align-items: $align;
}

// 绝对定位居中
@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 固定宽高比
@mixin aspect-ratio($width: 1, $height: 1) {
  position: relative;
  &::before {
    content: '';
    display: block;
    padding-top: math.div($height, $width) * 100%;
  }
}

// 1px边框
@mixin hairline($position: bottom, $color: $border-color) {
  position: relative;
  &::after {
    content: '';
    position: absolute;
    #{$position}: 0;
    left: 0;
    right: 0;
    height: 1px;
    background-color: $color;
    transform: scaleY(0.5);
    transform-origin: 50% 100%;
  }
}

// 响应式断点
@mixin respond-to($breakpoint) {
  @if $breakpoint == 'phone' {
    @media (max-width: 767px) { @content; }
  }
  @else if $breakpoint == 'tablet' {
    @media (min-width: 768px) and (max-width: 1024px) { @content; }
  }
  @else if $breakpoint == 'desktop' {
    @media (min-width: 1025px) { @content; }
  }
}

// 渐变背景
@mixin gradient($start-color: $primary-color, $end-color: lighten($primary-color, 15%), $direction: to right) {
  background: linear-gradient($direction, $start-color, $end-color);
}

// 清除浮动
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

// 禁止选择文本
@mixin no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
